﻿// 模式对话框
var v_showModalDialog = function(URL, vWidth, vHeight, isreload) {
    var childReturnValue = null;
    var strOptions = "dialogWidth:" + vWidth + "px;dialogHeight:" + vHeight
	    + "px;center:true;status:no;scrollbars:no;";
    var strURL = URL

    childReturnValue = window.showModalDialog(strURL, window, strOptions);
    if (isreload == true) {
	window.location.reload();
    }
    // document.RegMember.Member.focus();
}
//非模式对话框,弹出新的小窗口,IE下如果打开设置为TAB无效;
//打开地址URL,新窗口标题TITLE,是否有滚动条isscollbar(NO/YES);
var v_ModalDialog_x = function(Url, title, vwidth, vheight, isscollbar) {
    popupWin = window.open(Url, title, 'width=' + vwidth + ',height=' + vheight
	    + ',scrollbars=' + isscollbar
	    + ',toolbar=no, menubar=no, resizable=no,location=no, status=no')
}

var Check_Id_Window = function(value) {
    if (value == "") {
	alert("\请输入您要注册的会员名！");
	document.RegMember.Member.focus();
    } else if (CheckIfNumber(value)) {
	alert("\会员名不能全为数字！");
	document.RegMember.Member.focus();
    } else if (!CheckIfEnglish(value)) {
	alert("\您输入的会员名不符合规范！");
	document.RegMember.Member.focus();
    } else if ((value).length < 4) {
	alert("\会员名至少4位！");
	document.RegMember.Member.focus();
    } else {
	new v_showModalDialog("Check_Id.asp?Member=" + value, 300, 150, false);
    }
}

var showNewsDialg = function(ClsID, ID) {
    new v_showModalDialog("ShowNews.asp?ClsID=" + ClsID + "&ID=" + ID, 550,
	    350, false);
}

var showNewsDialgTech = function(ClsID, ID) {
    new v_showModalDialog("ShowNews.asp?ClsID=" + ClsID + "&ID=" + ID, 550,
	    410, false);
}

var Pingjia = function(ClsID, ID) {
    new v_ModalDialog_x("Oper.asp?ClsID=" + ClsID + "&ID=" + ID
	    + "&Oper=PINGJIA", '', 500, 400, "no")
}

var SchedulingDialg = function(ClsID, ID) {
    // new
    // v_showModalDialog("Oper.asp?ClsID="+ClsID+"&ID="+ID+"&Oper=SCHEDULING",400,220,true);
    new v_ModalDialog_x("Oper.asp?ClsID=" + ClsID + "&ID=" + ID
	    + "&Oper=SCHEDULING", '', 500, 400, "no")
}

var OverWorkDialg = function(ClsID, ID) {
    new v_ModalDialog_x("Oper.asp?ClsID=" + ClsID + "&ID=" + ID
	    + "&Oper=OVERWORKDIALG", '', 500, 220, "no")
}

//根据用户查看其对应的设置信息
var ShowTradInfo = function(userKey){
    new v_ModalDialog_x("TradInfo.asp?UserKey=" + userKey +"&Oper=SHOWTRADINFO", '', 600, 300, "YES")
}
// 在线处理
var OnlineWorkDialg = function(ClsID, ID) {
    new v_ModalDialog_x("Oper.asp?ClsID=" + ClsID + "&ID=" + ID
	    + "&Oper=ONLINEWORKDIALG", '', 600, 400, "no")
}

var EditMember = function(UserKey) {
    new v_ModalDialog_x("Oper.asp?UserKey=" + UserKey + "&Oper=EDITMEMBERINFO",
	    '', 500, 435, "yes")
}

var ShowUserInfo = function(UserKey) {
    new v_showModalDialog("ShowUser.asp?UserKey=" + UserKey, 450, 380, false);
}

// 删除并判断空格
var spaces = function(v) {
    v = v.replace(/ /gi, "");
    var len = 0;
    for (i = 0; i < v.length; i++)
	if (v.charCodeAt(i) > 256)
	    len += 2;
	else
	    len++;
    return len;
}
// 去掉所含空格<前中后>
var space = function(v) {
    v = v.replace(/ /gi, "");
    return v;
}
// 检验会员名的合法性
var CheckIfEnglish = function(String) {
    var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_";
    var i;
    var c;
    for (i = 0; i < String.length; i++) {
	c = String.charAt(i);
	if (Letters.indexOf(c) < 0)
	    return false;
    }
    return true;
}

var CheckIfNumber = function(String) {
    var Letters = "0123456789";
    var i;
    var c;
    var n = 0;
    for (i = 0; i < String.length; i++) {
	c = String.charAt(i);
	if (Letters.indexOf(c) >= 0) {
	    n++
	}
	;
    }
    if (n == String.length)
	return true;
}

// 只能输入数字
var OnlyNumber = function() {
    if (event.keyCode > 45 || event.keyCode < 57)
	event.returnValue = false;
}

// 检查email的合法性
var checkemail = function(inputstr) {
    if (inputstr.indexOf('@') != -1 && inputstr.indexOf('.') != -1)
	return true;
    else
	return false;
}
// 检验表单的合法性
var CheckFormRegMember = function() {
    if (document.RegMember.Member.value == "") {
	alert("\请输入您要注册的会员名！");
	document.RegMember.Member.focus();
    } else if (spaces(document.RegMember.Member.value) == 0) {
	alert("\请输入您要注册的会员名！\n提示：\n会员名不能是空格！");
	document.RegMember.Member.focus();
    } else if (CheckIfNumber(document.RegMember.Member.value)) {
	alert("\会员名不能全为数字！");
	document.RegMember.Member.focus();
    } else if (!CheckIfEnglish(document.RegMember.Member.value)) {
	alert("\您输入的会员名不符合规范！");
	document.RegMember.Member.focus();
    } else if ((document.RegMember.Member.value).length < 4) {
	alert("\会员名至少4位！");
	document.RegMember.Member.focus();
    } else if (document.RegMember.Password.value == "") {
	alert("\请输入密码！");
	document.RegMember.Password.focus();
    } else if (spaces(document.RegMember.Password.value) == 0) {
	alert("\请输入密码！\n提示：\n密码不能是空格！");
	document.RegMember.Password.focus();
    } else if ((document.RegMember.Password.value).length < 4) {
	alert("\密码至少4位！");
	document.RegMember.Password.focus();
    } else if (document.RegMember.PasswordTwo.value != document.RegMember.Password.value) {
	alert("\两次输入密码不相同！");
	document.RegMember.PasswordTwo.focus();
    } else if (document.RegMember.Email.value == "") {
	alert("\请输入您要注册的 E-Mail！");
	document.RegMember.Email.focus();
    } else if (document.RegMember.Email.value == ""
	    || !checkemail(document.RegMember.Email.value)) {
	alert("\请输入正确的 E-Mail！");
	document.RegMember.Email.focus();
    } else if (document.RegMember.ValidateCode.value == "") {
	alert("\请输入右侧的验证码！");
	document.RegMember.ValidateCode.focus();
    } else if ((document.RegMember.ValidateCode.value).length < 4) {
	alert("\验证码至少4位！");
	document.RegMember.ValidateCode.focus();
    } else if (!CheckIfNumber(document.RegMember.ValidateCode.value)) {
	alert("\验证码只能为数字！");
	document.RegMember.ValidateCode.focus();
    }
    else if (document.RegMember.RealName.value == "") {
	alert("\请输入联系人姓名！");
	document.RegMember.RealName.focus();
    } else if (document.RegMember.Tel.value == "") {
	alert("\请输入电话！");
	document.RegMember.Tel.focus();
    } else if (((document.RegMember.Tel.value).length < 7)
	    || ((document.RegMember.Tel.value).length > 13)) {
	alert("\请输入正确电话号码，EX-021-88888888！");
	document.RegMember.Tel.focus();
    } else if (spaces(document.RegMember.Address.value) == 0) {
	alert("\请输入地址！");
	document.RegMember.Address.focus();
    }
    else {
	return true;
    }
    return false;
}

var CheckFormEditUser = function() {
    if (space(document.EditUserForm.passwordNew.value) !=""){
	if (space(document.EditUserForm.passwordNew.value).length < 4){
	    alert("修改的密码不可小于四位");
	    document.EditUserForm.passwordNew.focus();
	}else{
	    return true;
	}
    }else if (document.EditUserForm.Email.value == "") {
	alert("\请输入您要注册的 E-Mail！");
	document.EditUserForm.Email.focus();
    } else if (document.EditUserForm.Email.value == ""
	    || !checkemail(document.EditUserForm.Email.value)) {
	alert("\请输入正确的 E-Mail！");
	document.EditUserForm.Email.focus();
    } else if (document.EditUserForm.RealName.value == "") {
	alert("\请输入真实姓名！");
	document.EditUserForm.RealName.focus();
    } else if (document.EditUserForm.Tel.value == "") {
	alert("\请输入电话！");
	document.EditUserForm.Tel.focus();
    } else if (((document.EditUserForm.Tel.value).length < 7)
	    || ((document.EditUserForm.Tel.value).length > 13)) {
	alert("\请输入正确电话号码，EX-021-88888888！");
	document.EditUserForm.Tel.focus();
    } else if (spaces(document.EditUserForm.Address.value) == 0) {
	alert("\请输入地址！");
	document.EditUserForm.Address.focus();
    } else {
	return true;
    }
    return false;
}

var CheckLoginForm = function() {
    if (spaces(document.Logon.Account.value) == 0) {
	alert("\请输入您的用户名！");
	document.Logon.Account.focus();
    } else if ((document.Logon.Account.value).length < 4) {
	alert("\用户名至少4位！");
	document.Logon.Account.focus();
    } else if (spaces(document.Logon.Password.value) == 0) {
	alert("\请输入您的密码！");
	document.Logon.Password.focus();
    } else if ((document.Logon.Password.value).length < 4) {
	alert("\密码至少4位！");
	document.Logon.Password.focus();
    } else if (document.Logon.ValidateCode.value == "") {
	alert("\请输入右边验证码！");
	document.Logon.ValidateCode.focus();
    } else if ((document.Logon.ValidateCode.value).length < 4) {
	alert("\验证码至少4位！");
	document.Logon.ValidateCode.focus();
    } else if (!CheckIfNumber(document.Logon.ValidateCode.value)) {
	alert("\验证码只能为数字！");
	document.Logon.ValidateCode.focus();
    } else {
	return true;
    }
    return false;
}

var FindPwdForm = function() {
    if (document.FindPwd.Email.value == "") {
	alert("\E-Mail 不能为空！");
	document.FindPwd.Email.focus();
    } else if (document.FindPwd.Email.value == ""
	    || !checkemail(document.FindPwd.Email.value)) {
	alert("\请正确输入您的E-Mail！");
	document.FindPwd.Email.focus();
    } else {
	return true;
    }
    return false;
}

var CheckFormAddMach = function() {
    if (document.ADDMACH.UserKey.value == "0") {
	alert("请选择设备所属的客户名称！");
	document.ADDMACH.UserKey.focus();
    }else if (document.ADDMACH.MID.value == "") {
	alert("设备编号不可为空！");
	document.ADDMACH.MID.focus();
    } else if (document.ADDMACH.MNAME.value == "") {
	alert("设备名称不可为空！");
	document.ADDMACH.MNAME.focus();
    }else {
	return true;
    }
    return false;
}

var CheckAddNewComm = function(){
    if (document.AddForm.Topic.value == "") {
	alert("\n请输入投诉标题！");
	document.AddForm.Topic.focus();
    }else if (eWebEditor1.getHTML()=="") {
	alert("\n请输入投诉内容！");
	return false;
   }else {
	return true;
    }
    return false;
}

// var addFavorite = function(url,vName) {
// window.external.addFavorite(url,vName);
// }

// 使用方法：<a onclick="addFavorite(window.location,document.title)">加入收藏</a>
var addFavorite = function(sURL, sTitle) {
    try {
	window.external.addFavorite(sURL, sTitle);
    } catch (e) {
	try {
	    window.sidebar.addPanel(sTitle, sURL, "");
	} catch (e) {
	    alert("加入收藏失败，请使用Ctrl+D进行添加");
	}
    }
}

// 使用方法：<a onclick="SetHome(this,window.location)">设为首页</a>
var SetHome = function(obj, vrl) {
    try {
	obj.style.behavior = 'url(#default#homepage)';
	obj.setHomePage(vrl);
    } catch (e) {
	if (window.netscape) {
	    try {
		netscape.security.PrivilegeManager
			.enablePrivilege("UniversalXPConnect");
	    } catch (e) {
		alert("此操作被浏览器拒绝！请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
	    }
	    var prefs = Components.classes['@mozilla.org/preferences-service;1']
		    .getService(Components.interfaces.nsIPrefBranch);
	    prefs.setCharPref('browser.startup.homepage', vrl);
	}
    }
}

var FeedBack = function() {
    if (document.FeedBackForm.Runce.value == "") {
	alert("\不能为空！");
	document.FeedBackForm.Runce.focus();
    } else if (document.FeedBackForm.Nums.value == "") {
	alert("\数量最小为1！");
	document.FeedBackForm.Nums.focus();
    } else if (document.FeedBackForm.ContactMan.value == "") {
	alert("\联系人不可为空");
	document.FeedBackForm.ContactMan.focus();
    } else if (document.FeedBackForm.Tel.value == "") {
	alert("\必须输入您的联系方式！Ex:021-88888888");
	document.FeedBackForm.Tel.focus();
    } else if (document.FeedBackForm.Email.value == "") {
	alert("\必须输入您的联系方式！Ex:admin@admin.com");
	document.FeedBackForm.Email.focus();
    } else {
	return true;
    }
    return false;
}

var CheckAddNew = function() {
   if ($("#UserName").val() == "" || $("#UserKey").val() == "0") {
		alert("\请搜索并选择客户名称！");
		$("#UserName").focus();
    } else if (document.AddForm.ClsID.value == "#") {
		alert("\请选择任务类型！");
		document.AddForm.ClsID.focus();
    } else if (document.AddForm.Topic.value == "") {
	alert("\信息标题不能为空！");
	document.AddForm.Topic.focus();
    }else if (document.AddForm.TechOneD.value == "选择日期") {
	alert("\预约上限时间中日期必须选择！");
	document.AddForm.TechOneD.focus();
    }else if (document.AddForm.TechOneT.value == "选择时间") {
	alert("\预约上限时间中时间必须选择！");
	document.AddForm.TechOneT.focus();
    }else if (document.AddForm.TechTwoD.value == "选择日期") {
	alert("\预约下限时间中日期必须选择！");
	document.AddForm.TechTwoD.focus();
    }else if (document.AddForm.TechTwoT.value == "选择时间") {
	alert("\预约下限时间中时间必须选择！");
	document.AddForm.TechTwoT.focus();
    }else if (document.AddForm.TechTwoD.value < document.AddForm.TechOneD.value) {
	alert("\预约下限时间必须有上限日期之后,请重新选择！");
	document.AddForm.TechTwoD.focus();
    }else {
	return true;
    }
    return false;
}


function Add30M(h,m) {
    try
    {
        if (h != "" || m != "") {
            var time = "2010-1-26 " ;
            var addtime = new Date(new Date(time.replace(/-/g, "/") + " " + h + ":" + m + ":" + "00").getTime() + 30 * 60 * 1000);
            return addtime.getHours() + ":" + addtime.getMinutes();
        }
        else
            return "";
    }
    catch(err)
    {
        return "";
    }
}

function getH(h) {
    if (h.length == 1)
        return h = "0" + h;
    else
        return h;
}
function getM(m) {
    if (m.length == 1)
        return m = "0" + m;
    else
        return m;
}